package org.etlt.load;

import org.etlt.util.SystemUtil;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class DatabaseLoaderSetting extends LoaderSetting {
    private List<String> preDmls = new ArrayList<>();

    private List<DmlSetting> dmls = new ArrayList<>();

    private int parallel = 1;

    public List<String> getPreDmls() {
        return preDmls;
    }

    public void setPreDmls(List<String> preDmls) {
        this.preDmls = preDmls;
    }

    public List<DmlSetting> getDmls() {
        return dmls;
    }

    public void setDmls(List<DmlSetting> dmls) {
        this.dmls = dmls;
    }

    @Deprecated
    public int getParallel() {
        return parallel;
    }

    /**
     * NOT supported now
     *
     * @param parallel
     */
    @Deprecated
    public void setParallel(int parallel) {
//todo
        //        this.parallel = parallel;
    }

    public void addPredml(String predml) {
        this.preDmls.add(predml);
    }

    public void addDml(DmlSetting dml) {
        if(this.dmls.contains(dml)){
            throw new IllegalArgumentException("duplicated dml setting found: " + dml.getId() + " in " + getName());
        }
        this.dmls.add(dml);
    }

    @Override
    public void check() {
        super.check();
        assertName("name", getName());
        assertFalse("dml must exist", !this.dmls.isEmpty());
        assertNotNull("datasource", this.getDatasource());
        assertFalse("parallel must be greater than 0.", getParallel() > 0);
        assertFalse("parallel must be less than cpu size:" + SystemUtil.getCpuCount(), getParallel() <= SystemUtil.getCpuCount());
    }


}
